﻿@using Jb.Framework.Common.Forms
@using Jb.Framework.Common.Forms.Validation;
@using Jb.Framework.Web.Mvc
@model Jb.Framework.Common.Forms.JbDropDown

@{

    var textBoxHtmlAttr = new Dictionary<string, object>();
    InputHelper.InputAccessible(Model, (VisibilityMode)ViewBag.VisibleMode, ref textBoxHtmlAttr);
    textBoxHtmlAttr.Add("class", "input-large"); // @Salman please add your style here 

    textBoxHtmlAttr.Add("placeholder", string.IsNullOrEmpty(Model.HelpText) ? string.Empty : Model.HelpText);

    if (Model.Validations.Any(x => x.Type != ElementValidationType.None))
    {
        textBoxHtmlAttr.Add("data-val", "true");
    }
    if (Model.Validations.Any(x => x.Type == ElementValidationType.Required))
    {
        textBoxHtmlAttr.Add("data-Val-Required", Model.Validations.First(x => x.Type == ElementValidationType.Required).Message);
    }

    var titlevalue = Model.Title;

    // if field is required add star
    if (Model.Validations.Any(t => t.Type == ElementValidationType.Required))
    {
        titlevalue += " <span class='star'>*</span>";
    }
    var labelHtmlAttr = new Dictionary<string, object> { { "class", "Custom-label" }, { "data-value", titlevalue } };
    
}

<div class="pull-left form-group" style="display: @(Model.VisibleMode != VisibilityMode.Both && Model.VisibleMode != (VisibilityMode)ViewBag.VisibleMode ? "none" : "block")">   
    @Html.HiddenFor(m => m.JsonItems)
    <!--To Bind Label to its textbox -->
    @Html.LabelFor(x => x.Value, labelHtmlAttr)
    
    @Html.GenerateHiddenFields(Model)

    @foreach (var accRole in Model.AccessRole)
    { 
        @Html.HiddenFor(modelItem => accRole)
    }

    @Html.DropDownListFor(model => model.Value, Model.Items.Select(item => new SelectListItem() { Value = item.Value, Text = item.Text }), htmlAttributes: textBoxHtmlAttr)
    @if (!string.IsNullOrEmpty(Model.HelpText))
    {
        <a class="name-info" data-container="body" rel="popover" data-placement="top" data-content="@Model.HelpText"></a>
    }
    @Html.ValidationMessageFor(model => model.Value)

</div>

<script type="text/javascript">

    //get data-value and set to html to correct show value
    $(".Custom-label").each(function () {
        // alert($(this).data("value"));
        $(this).html($(this).data("value"));
    });

</script>



